// $Id: queue.h 4 2011-10-20 16:07:10Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef QUEUE_H_
#define QUEUE_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <sys/queue.h>

#define TAILQ_FOREACH_SAFE(var, head, field, next_var)                  \
        for ((var) = ((head)->tqh_first);                               \
                (var) && ((next_var) = ((var)->field.tqe_next), 1);     \
                (var) = (next_var))

#include <zcbuffer.h>

struct zcbuffer;

struct zcqueue_item {
	struct timeval timestamp;
	struct zcbuffer *buffer;
	TAILQ_ENTRY(zcqueue_item) entry;
};

TAILQ_HEAD(zcqueue_head, zcqueue_item);

struct zcqueue {
	struct zcqueue_head caches;
	struct zcqueue_head head;
	size_t size;
};

#ifdef __cplusplus
}
#endif

#endif /* QUEUE_H_ */
